<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('编辑用印信息')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-info-add" th:object="${vo}">
            <input id="caseId" name="chopId" type="hidden" th:field="*{chopId}"/>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">用印名称：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" th:field="*{chopName}" required>
                </div>
            </div>
            
            <div class="form-group">
	            <div id="element_ct">
            		<label class="col-sm-3 control-label is-required">印章类型：</label>
                       <div class="col-sm-2">
                         <select class="type form-control m-b" th:field="*{chopGroup}" required data-first-title="请选择">
		                  	<option value="">请选择</option>
		                  	<option th:value="*{chopGroup}" th:selected="1"></option>
		                </select>
	                </div>
		            <label class="col-sm-3 control-label is-required">申请类型：</label>
		            <div class="col-sm-2">
		                <select class="router form-control m-b" th:field="*{chopTypeId}" required data-first-title="请选择">
		                  <option value="">请选择</option>
		                  <option th:value="*{chopTypeId}" th:selected="1"></option>
		                </select>
		           </div>
	            </div>
            </div>
            
            <div class="form-group">
	            <div>
            		<label class="col-sm-3 control-label is-required">何种印章：</label>
	                <div class="col-sm-2">
			 			<select class="form-control m-b" th:field="*{sealTypeId}" required>
			            <option value="">请选择</option>
				 		<option th:each="u : ${sealTypes}" th:text="${u.name}" th:value="${u.id}" th:field="*{sealTypeId}"></option>
						</select>
	               </div>
		           <label class="col-sm-3 control-label is-required">文件份数：</label>
		           <div class="col-sm-2">
		              <input type="text" class="router form-control m-b" th:field="*{copies}" required>
		           </div>
	            </div>
            </div>
            
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">用印状态：</label>
                    <div id="element_chop_status" class="row">
                        <div class="col-sm-2">
			             	<select class="form-control m-b" th:field="*{status}" disabled="true" required>
			                    <option value="">请选择</option>
				      			<option th:each="u : ${chopStatus}" th:text="${u.name}" th:value="${u.id}" th:field="*{status}"></option>
				   			</select>
		                </div>
                	</div>
            </div>
            
            <div class="form-group">
                <label class="col-sm-3 control-label">案件编码：</label>
                <div class="col-sm-8">
          		   <div class="input-group" name='div_principal_input'>
                 		<!-- hidden begin -->
         				<input type="hidden" th:field="*{caseNo}" />
						<!-- hidden end -->
						<input name="caseSelect" id="caseSelect" type="text" placeholder="请选择案件" class="form-control" readonly="true"
                    	    th:value="${ (vo.caseInfo != null && vo.caseNo != null) ? (vo.caseNo + '-' + vo.caseInfo.caseName) : (vo.caseNo) }" >
                    	<span name="selectUserInfo" class="input-group-addon" 
                    		th:onclick="${vo.status != curStatus} ? 'javascript:void(0)' : 'selectUserInfo_principal()'" 
                    		th:disabled="${vo.status != curStatus}"><i class="fa fa-search"></i></span>
                    	<span name="deleteRow" class="input-group-addon" 
                    		th:onclick="${vo.status != curStatus} ? 'javascript:void(0)' : 'deleteRow_principal()'" 
                    		th:disabled="${vo.status != curStatus}"><i class="fa fa-minus"></i></span>
                  </div>
		      </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input name="remark" class="form-control" type="text" th:field="*{remark}">
                </div>
            </div>
        </form>
 
	     <div class="form-horizontal m" id="div-info-add" readonly>
	            <div class="form-group">
	                <label class="col-sm-3 control-label">用印文件:</label>
	                <!-- 用印文件 -->
	                <div id="element_chop_files" class="row">                                                                                                                                     
	                 	<div class="col-sm-8">
			            	<table>
						    <thead>
						    <tr>
						        <th width="2%">No.</th>
						        <th width="23%">文件名</th>
						        <th width="40%">文件状态</th>
						        <th width="25%">备注</th>
						    </tr>
						    </thead>
			            	<tbody>
			            	  <tr>
			            	  	<td>
			            	  	</td>
			            	    <td>
	 				                <form method="post" id="form_upload"
					                	th:action="@{/office/chopinfo/enroll/upload}"
					                	enctype="multipart/form-data" th:if="${vo.status == curStatus}">
							          <input type="hidden" name="id" th:value="${vo.chopId}">
				                      <input type="file" name="file">
					                </form>
				                </td>
			            	    <td>
				                    &nbsp;&nbsp;&nbsp;&nbsp;
	 			                    <a href="javascript:void(0)" name="btn_upload" th:if="${vo.status == curStatus}" 
				 						onclick="form_upload.submit()">上传</a>
			            	    </td>
			            	    <td>
			            	  	  <label th:if="${message ne null}" class="alert alert-primary">[[${message}]]</label>
			            	    </td>
			            	  </tr>
	 				          <tr th:each="file, fileStat:${vo.files}" th:unless="${#lists.isEmpty(vo.files)}">
					            <td>[[${fileStat.index+1}]].&nbsp;</td>
					            <td>[[${file.name}]]</td>
					            <td>
					              <a name="btn_download"
					                th:href="@{'/office/chopinfo/enroll/download/' + ${vo.chopId} + '/' + ${file.name}}">下载</a>
					                &nbsp;&nbsp;
					              <a th:href="@{'/office/chopinfo/enroll/delete/' + ${vo.chopId} + '/' + ${file.name}}" 
					              	th:fileName="${file.name}" name="btn_delete" title="Delete this file" 
					              	  th:if="${vo.status == curStatus}"
					              		th:onclick="return confirm('是否确定删除['+[[${file.name}]]+']?')">删除</a>
					            </td>
					          </tr>
					     </tbody>
			             </table>
				 </div>
	           </div>
	        </div>
	     </div>

    </div>
    <!-- [[${vo.chopId}]]/[[${vo.status}]]/[[${curStatus}]] -->
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
        	<span th:if="${vo.status == curStatus}">
            	<button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-save"></i>保 存</button>&nbsp;
            	<button type="button" class="btn btn-sm btn-primary" th:onclick="applyHandler([[${vo.chopId}]])"><i class="fa fa-check"></i>申 请</button>&nbsp;
            </span>
            <span th:if="${vo.status != curStatus}">
            	<button type="button" class="btn btn-sm btn-default" onclick="javascript:void(0)" disabled="true"><i class="fa fa-save"></i>保 存</button>&nbsp;
            	<button type="button" class="btn btn-sm btn-default" onclick="javascript:void(0)" disabled="true"><i class="fa fa-save"></i>申 请</button>&nbsp;
            </span>
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: jquery-cxselect-js" />

    <script th:inline="javascript">
        var prefix = ctx + "office/chopinfo/refuse"
        $("#form-info-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
			let caseNo = $('#caseNo').val();
			if (caseNo == null) {
	   			$('#caseNo').val("");
			}
   			doSubmitHandler();
        }
        
        function doSubmitHandler() {
	    	$.ajax({
	            url: prefix + "/edit",
	            data: $('#form-info-add').serialize(),
	            type: "post",
	            success: function(result) {
	            	if (result.code == web_status.SUCCESS) {
	            		layer.msg("保存成功,正在刷新数据请稍候……", {
		            	    icon: 1,
		            	    time: 500,
		            	    shade: [0.1, '#8F8F8F']
		            	},function() {
		            		location.reload();
		            	});
	            	} else {
	            		alert(result.msg);
	            	}
	            }
	        })
        }

        function applyHandler(chopId) {
        	$.modal.confirm("确认真的要提交申请吗?", function() {
        		doApplyHandler(chopId);
    		});
        }
        
        function doApplyHandler(chopId) {
	    	$.ajax({
	            url: prefix + "/apply",
	            data: $('#form-info-add').serialize(),
	            type: "post",
	            success: function(result) {
	            	if (result.code == web_status.SUCCESS) {
	            		layer.msg("申请成功,正在刷新数据请稍候……", {
		            	    icon: 1,
		            	    time: 500,
		            	    shade: [0.1, '#8F8F8F']
		            	},function() {
		            		/* window.location.href = prefix + "/view/" + chopId; */
		            		location.reload();
		            		/* $.modal.openTab("修改用章信息", prefix + "/edit/" + chopId); */
		            		ctrlform();
		            	});
	            	} else {
	            		alert(result.msg);
	            	}
	            }
	        })
        }
        
        /* 客户管理-新增-选择客户 */
        function selectUserInfo_principal() {
        	var url = ctx + "biz/caseinfo/inquiry/choice";
			var options = {
				title: '选择案件',
				width: "980",
				height: "680",
				url: url,
				callBack: doSubmitUserInfo_principal
			};
			$.modal.openOptions(options);
		}
        
        /* 选择客户后，进行相应的赋值 */
		function doSubmitUserInfo_principal(index, layero) {
			var body = $.modal.getChildFrame(index);
			/* set val */
			
			let caseNo = body.find('#caseNo').val();
			let caseName = body.find('#caseName').val();

			if (caseNo == null) {
				caseNo = "";
			}
   			$('#caseNo').val(caseNo);

			var cs_val = $.common.sprintf('(%s-%s)', caseNo, caseName);
			$('#caseSelect').val(cs_val);
			//
   			$.modal.close(index);
		}

        /* 用户管理-新增-选择部门树 */
        function deleteRow_principal() {
   			$('#caseNo').val('');

			var cs_val = '';
			$('#caseSelect').val(cs_val);
		}
        
        function ctrlform() {
    		$('#form-info-add').find('input').attr('readonly',true);
    		$('#form-info-add').find('radio').attr('readonly',true);
    		$('#form-info-add').find('select').attr('readonly',true);
    		$('#form-info-add').find('select').attr('disabled',true);
    		$('#form-info-add').find('button').attr('readonly',true);
    		$('#form-info-add').find('button').attr('disabled',true);
        }
        
    </script>
   
	<script th:inline="javascript">
		// 直接返回获取
		var ctData = [[${ctData}]];
		$('#element_ct').cxSelect({
		  selects: ['type', 'router'],
		  jsonValue: 'v',
		  data: ctData
		});
	</script>
    
</body>
</html>